
#include "telnet.h"

Telnet::Telnet(QString hostName, quint16 port, QObject* parent)
	:QObject(parent)
{
	s = new QTcpSocket(this);
	s->connectToHost(hostName, port);
	qDebug() << "Connection status: " << s->isValid();
	connect(s, SIGNAL(readyRead()), this, SLOT(readData()));
}

void Telnet::readData() {
	qDebug() << "Data read";
	QByteArray buf;
	buf = s->readAll();	
	messages.append(QString(buf));
}

void Telnet::debugPrintMes() {
		qDebug() << "debugPrintMes()";
		for (int i = 0; i < messages.count(); i++) {
			qDebug() << messages[i];
		}
}

qint64 Telnet::writeData(char * data) {
		QByteArray buf(data);
		buf.append("\n\n");
		return s->write(buf);
}

QVector<QString> Telnet::getResponse() {
		return messages;
}
